package com.example.mantenimientovehiculo.repostaje;

import java.util.ArrayList;

import android.database.Cursor;

public final class Repostajes extends ArrayList<Repostaje> {
	/**
	 * 
	 */
	private static final long serialVersionUID = 4176192527313634141L;

	/**
	 * 
	 */
	public Repostajes() {
		super();
		// TODO Apéndice de constructor generado automáticamente
	}	
	
	public Repostaje cursorActualToRepostaje(Cursor c){
		Repostaje repos = new Repostaje();
		repos.setId_historicorepostar(Integer.parseInt(c.getString(c
				.getColumnIndex("id_historicorepostar"))));
		repos.setsFecha(c.getString(c.getColumnIndex("fecha")));
		repos.setiKilometros(Integer.parseInt(c.getString(c
				.getColumnIndex("kilometros"))));
		repos.setDblLitros(Double.parseDouble(c.getString(c
				.getColumnIndex("litros"))));
		repos.setDblPrecio(Double.parseDouble(c.getString(c
				.getColumnIndex("preciolitro"))));
		repos.setbDepositoLleno(Integer.parseInt(c.getString(c.getColumnIndex("deposito_lleno"))));
		return repos;
	}
	
	public void addAllFromCursor(Cursor c){
		// Nos aseguramos de que existe al menos un registro
		if (c.moveToFirst()) {
			do {
				Repostaje repos = cursorActualToRepostaje(c);
				if (this.contains(repos) == false){
					this.add(repos);
				}				
			} while (c.moveToNext());
		}
	}
	
}